package com.cjy.hd12;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class Tripltem implements WritableComparable<Tripltem> {
    private String vin;
    private int mileage;
    private int minutes;

    public Tripltem() {
    }

    public Tripltem(String vin, int mileage, int minutes) {
        this.vin = vin;
        this.mileage = mileage;
        this.minutes = minutes;
    }

    public String getVin() {
        return vin;
    }

    public void setVin(String vin) {
        this.vin = vin;
    }

    public int getMileage() {
        return mileage;
    }

    public void setMileage(int mileage) {
        this.mileage = mileage;
    }

    public int getMinutes() {
        return minutes;
    }

    public void setMinutes(int minutes) {
        this.minutes = minutes;
    }

    @Override
    public String toString() {
        return "Tripltem{" +
                "vin='" + vin + '\'' +
                ", mileage=" + mileage +
                ", minutes=" + minutes +
                '}';
    }

    @Override
    public int compareTo(Tripltem o) {
        if (mileage>o.getMileage()){
            return -1;
        }else if (mileage==o.mileage){
            if (minutes>o.getMinutes()){
                return 1;
            }else if(minutes==o.minutes){
                return 0;
            }else {
                return -1;
            }
        }else {
            return 1;
        }
    }

    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeUTF(this.vin);
        dataOutput.writeInt(this.mileage);
        dataOutput.writeInt(this.minutes);
    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
        this.vin = dataInput.readUTF();
        this.mileage = dataInput.readInt();
        this.minutes = dataInput.readInt();
    }
}
